package com.sskj.gocoin.mine;


import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.gocoin.R;
import com.sskj.gocoin.R2;
import com.sskj.gocoin.common.widget.ToolBarLayout;
import com.sskj.gocoin.component.DaggerUserDataComponent;
import com.sskj.gocoin.m.bean.ShareEntry;
import com.sskj.gocoin.utils.APKVersionCodeUtils;
import com.sskj.gocoin.utils.ClickUtil;
import com.sskj.gocoin.utils.LanguageUtil;
import com.sskj.gocoin.utils.PhoneHideUtil;
import com.sskj.gocoin.v.activity.InviteFriendActivity;
import com.sskj.gocoin.v.activity.ShareActivity;
import com.sskj.gocoin.v.activity.WebViewActivity;
import com.sskj.gocoin.v.base.BaseActivity;
import com.sskj.lib.RConfig;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * 我的推广
 */
public class MyShareActivity extends BaseActivity<MySharePresenter> {
    @BindView(R2.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R2.id.share_count)
    TextView shareCount;
    @BindView(R2.id.share_get)
    TextView shareGet;
    @BindView(R2.id.tv_friends)
    TextView tvFriends;
    @BindView(R2.id.tv_go_share)
    TextView tvGoShare;
    @BindView(R2.id.tv_get_detail)
    TextView tvGetDetail;
    @BindView(R2.id.rules)
    TextView rules;
    @BindView(R2.id.service)
    TextView service;
    @BindView(R2.id.version)
    TextView version;
    @BindView(R2.id.facebook)
    ImageView facebook;
    @BindView(R2.id.twitter)
    ImageView twitter;
    @BindView(R2.id.github)
    ImageView github;
    @BindView(R2.id.iv_my_share_vip)
    ImageView vipIv;
    @BindView(R2.id.tv_my_share_name)
    TextView nameTv;
    @BindView(R2.id.tv_my_share_hb)
    TextView hbTv;
    @BindView(R2.id.tv_my_share_djfygz)
    TextView djfygzTv;

    @BindView(R2.id.tvFreeCount)
    TextView tvFreeCount;
    @BindView(R2.id.tvKhCount)
    TextView tvKhCount;
    @BindView(R2.id.tvTodayCount)
    TextView tvTodayCount;
    @BindView(R2.id.tvAllMoney)
    TextView tvAllMoney;
    @BindView(R2.id.ivBg)
    ImageView ivBg;


    @Inject
    UserViewModel userViewModel;
    private UserData userData;

    @Override
    public MySharePresenter getPresenter() {
        return new MySharePresenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickLinster(v -> finish());

        DaggerUserDataComponent.create().inject(this);
        userViewModel.getUsers().observe(this, users -> {
            if (users != null && users.size() > 0) {
                userData = users.get(0);

//                if (!userData.getAccount().contains("@")) {
//                    nameTv.setText(PhoneHideUtil.getHide(userData.getAccount()));
//                } else {
//                    nameTv.setText(PhoneHideUtil.getEmailHide(userData.getAccount()));
//                }

                nameTv.setText(userData.getMobile());
            }
        });

        if (LanguageUtil.isChinese()) {
            ivBg.setImageResource(R.mipmap.mine_share_bg);
        }else {
            ivBg.setImageResource(R.mipmap.mine_share_bg_en1);
        }

        ClickUtil.click(tvFriends, new ClickUtil.Click() {
            @Override
            public void click() {
//                InviteFriendActivity.start(MyShareActivity.this);
                ShareActivity.start(MyShareActivity.this);
            }
        });
//        ClickUtil.click(tvGoShare, () -> startActivity(new Intent(this, ShareActivity.class)));
        ClickUtil.click(tvGoShare, () -> MyFriendsActivity.start(this));
        ClickUtil.click(tvGetDetail, new ClickUtil.Click() {
            @Override
            public void click() {
//                ARouter.getInstance().build(RConfig.MINE_COMMON_DETAIL).withInt("type", 3).navigation();
                MoneyDetailActivity.start(MyShareActivity.this);
            }
        });
        ClickUtil.click(hbTv, new ClickUtil.Click() {
            @Override
            public void click() {
                HBActivity.start(MyShareActivity.this);
            }
        });

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_my_share_n;
    }

    @Override
    public void initData() {
        mPresenter.getData(1);
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, MyShareActivity.class);
        context.startActivity(intent);
    }

    public void setData(ShareEntry data) {
        setText(tvKhCount, data.getKqnums());
        setText(tvTodayCount, data.getJintiansy());
        setText(tvAllMoney, data.getZongsy());
        setText(tvFreeCount, data.getMfkqnums());
    }

}
